package top.houry.im.server.common;

import com.google.protobuf.ByteString;
import top.houry.im.server.enums.ImServerResultEnum;
import top.houry.im.server.proto.ImMessage;

public class Server {


    public static ImMessage.Server success(String msgType, ByteString bytes) {
        return success(msgType, bytes, ImServerResultEnum.SUCCESS.getCode(), ImServerResultEnum.SUCCESS.getMsg());
    }


    public static ImMessage.Server success(String msgType, ByteString bytes, String msgTip) {
        return success(msgType, bytes, ImServerResultEnum.SUCCESS.getCode(), msgTip);
    }

    public static ImMessage.Server success(String msgType, ByteString bytes, int code, String msgTip) {
        ImMessage.Server.Builder resp = ImMessage.Server.newBuilder();
        resp.setMsgType(msgType);
        resp.setBytesData(bytes);
        resp.setCode(code);
        resp.setMsgTip(msgTip);
        return resp.build();
    }

    public static ImMessage.Server error() {
        return success("", null, ImServerResultEnum.SERVER_ERROR.getCode(), ImServerResultEnum.SERVER_ERROR.getMsg());
    }

    public static ImMessage.Server fail(String msgType, ByteString bytes) {
        return fail(msgType, bytes, ImServerResultEnum.OPERATOR_ERROR.getCode(), ImServerResultEnum.OPERATOR_ERROR.getMsg());
    }

    public static ImMessage.Server fail(String msgType) {
        return fail(msgType, null, ImServerResultEnum.OPERATOR_ERROR.getCode(), ImServerResultEnum.OPERATOR_ERROR.getMsg());
    }

    public static ImMessage.Server fail(String msgType, ImServerResultEnum enums) {
        return fail(msgType, null, enums.getCode(), enums.getMsg());
    }

    public static ImMessage.Server fail(String msgType, ByteString bytes, int code, String msgTip) {
        ImMessage.Server.Builder resp = ImMessage.Server.newBuilder();
        resp.setMsgType(msgType);
        resp.setBytesData(bytes);
        resp.setCode(code);
        resp.setMsgTip(msgTip);
        return resp.build();
    }


}
